package com.deathbase;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Configurable;

import com.vaadin.Application;
import com.vaadin.terminal.gwt.server.HttpServletRequestListener;
import com.vaadin.ui.Window;

@Configurable
public class DeathBaseApplication extends Application implements
		HttpServletRequestListener {
	
	private static final long serialVersionUID = 1L;

	public static final String APPLICATION_TITLE = "Vaading-Spring Demo";

	private static ThreadLocal<DeathBaseApplication> currentApplication =
        new ThreadLocal<DeathBaseApplication> ();
	
	@Override
	public void init() {
		setInstance(this);
		setMainWindow(new Window("666"));
	}
	
	public static DeathBaseApplication getInstance() {
		return currentApplication.get();
	}
	
	public static void setInstance(DeathBaseApplication application) {
		currentApplication.set(application);
	}
	
	@Override
	public void onRequestStart(HttpServletRequest request,
			HttpServletResponse response) {
		setInstance(this);
	}

	@Override
	public void onRequestEnd(HttpServletRequest request,
			HttpServletResponse response) {
		currentApplication.remove();
	}

}
